<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<html>
<head>
	<title>中南·建投-PM管理平台</title>
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	<![endif]--> 
	<script type="text/javascript">
		// 系统退出
		function logout() {
			//layer.confirm('确定退出登录？',{icon:3, title :'提示'}, function(){
					window.top.location.href = "${ctx}/mgr/logout";
		    //  	});
		}
		
		// 修改密码
		function editPwd() {
			layer.open({
	          	  title: '修改密码'
	              ,type: 1
	              ,shadeClose: false
	              ,area: layui.admin.screen() < 2 ? ['80%', '320px'] : ['500px', '320px']
	              ,content: layui.$('#w_editpwd')
	            });
			layui.$('#oldpwd').val('');
			layui.$('#LAY_password').val('');
			layui.$('#repwd').val('');
		}
		
		// 切换公司部门
		function changeOrgDept() {
			layer.open({
	          	  title: '切换：当前公司—部门'
	              ,type: 1
	              ,shadeClose: false
	              ,area: layui.admin.screen() < 2 ? ['80%', '250px'] : ['500px', '250px']
	              ,content: layui.$('#w_change_org_dept')
	            });
		}
		
	</script>
</head>

<body class="layui-layout-body">
  
  <div id="LAY_app">
    <div class="layui-layout layui-layout-admin">
      <div class="layui-header">
        <!-- 头部区域 -->
        <ul class="layui-nav layui-layout-left">
          <li class="layui-nav-item layadmin-flexible" lay-unselect>
            <a href="javascript:;" layadmin-event="flexible" title="侧边伸缩">
              <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>
            </a>
          </li>
          <li class="layui-nav-item" lay-unselect>
            <a href="javascript:;" layadmin-event="refresh" title="刷新">
              <i class="layui-icon layui-icon-refresh-3"></i>
            </a>
          </li>
        </ul>
        <ul class="layui-nav layui-layout-right" lay-filter="layadmin-layout-right">
          <li class="layui-nav-item layui-hide-xs" lay-unselect>
            <a href="javascript:;" layadmin-event="theme" title="配色方案">
              <i class="layui-icon layui-icon-theme"></i>
            </a>
          </li>
          <li class="layui-nav-item layui-hide-xs" lay-unselect>
            <a href="javascript:;" layadmin-event="fullscreen"  title="全屏">
              <i class="layui-icon layui-icon-screen-full"></i>
            </a>
          </li>
          <li class="layui-nav-item" lay-unselect>
            <a href="javascript:javascript:changeOrgDept();" style="padding:0 5px;">
              <cite>当前公司—部门：<span style="text-decoration:underline;" id="showOrgDept"><c:choose><c:when test="${bindOrgName!=null}">${bindOrgName}—${bindDeptName}</c:when><c:otherwise><font color="red">未设置</font></c:otherwise></c:choose></span></cite>
            </a>
          </li>
          <li class="layui-nav-item" lay-unselect>
            <a href="javascript:;">
              <cite style="text-align: center;"><%=SessionUserUtils.getSessionUserName()%></cite>
            </a>
            <dl class="layui-nav-child">
              <dd style="text-align: center;"><a href="javascript:editPwd();">修改密码</a></dd>
              <hr>
              <dd style="text-align: center;"><a href="javascript:logout();">退出登录</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item layui-hide-xs" lay-unselect>
          	&nbsp;&nbsp;&nbsp;&nbsp;
          </li>
        </ul>
      </div>
      <!-- 修改密码div  -->
      <div id="w_editpwd" class="layui-fluid" style="display:none;">
	    <div class="layui-row layui-col-space15">
	      <div class="layui-col-md12">
	        <div class="layui-card">
	          <div class="layui-card-body" pad15>
	            
	            <div class="layui-form">
	              <div class="layui-form-item">
	                <label class="layui-form-label">原始密码</label>
	                <div class="layui-input-inline">
	                  <input id="oldpwd" type="password" name="oldpwd" lay-verify="required" lay-verType="tips" class="layui-input">
	                </div>
	              </div>
	              <div class="layui-form-item">
	                <label class="layui-form-label">新密码</label>
	                <div class="layui-input-inline">
	                  <input id="LAY_password" type="password" name="newpwd" lay-verify="required|pass" lay-verType="tips"  autocomplete="off" class="layui-input">
	                </div>
	                <div class="layui-form-mid layui-word-aux">8到16个字符</div>
	              </div>
	              <div class="layui-form-item">
	                <label class="layui-form-label">确认新密码</label>
	                <div class="layui-input-inline">
	                  <input id="repwd" type="password" name="renewpwd" lay-verify="repass" lay-verType="tips" autocomplete="off" class="layui-input">
	                </div>
	              </div>
	              <div class="layui-form-item" style="margin-top:10px;">
	                <div class="layui-input-block">
	                  <button class="layui-btn" lay-submit lay-filter="lay-edit-pwd-submit"/>确认修改</button>
		            </div>
	              </div>
	            </div>
	          </div>
	        </div>
	      </div>
	    </div>
	  </div>
      
      <!-- 切换公司/部门div  -->
      <div id="w_change_org_dept" class="layui-fluid" style="display:none;">
	    <div class="layui-row layui-col-space15">
	      <div class="layui-col-md12">
	        <div class="layui-card">
	          <div class="layui-card-body" pad15>
	            <div class="layui-form">
	              <div class="layui-inline">
		            <label class="layui-form-label">请选择</label>
		            <div class="layui-input-inline" style="width:277px;">
						<select  name="chosenOrgDeptId" id ="editOrg" lay-search>
							<c:if test="${not empty myAllOrgDept}">
								<c:forEach var="od" items="${myAllOrgDept}" > 
									<option value="${od.orgId}-${od.deptId}">${od.compName}—${od.deptName}</option>
								</c:forEach>
							</c:if>
						</select>
		            </div>
		          </div>
	              <div class="layui-form-item" style="margin-top:40px;">
	                <div class="layui-input-block">
	                  <button class="layui-btn" lay-submit lay-filter="lay-edit-org-submit"/>确认切换</button>
		            </div>
	              </div>
	            </div>
	          </div>
	        </div>
	      </div>
	    </div>
	  </div>
      
      <!-- 侧边菜单 -->
      <div class="layui-side layui-side-menu">
        <div class="layui-side-scroll">
          <div class="layui-logo">
            <span>PM管理平台</span>
          </div>
          <ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu" lay-filter="layadmin-system-side-menu">
		  </ul>
        </div>
      </div>

      <!-- 页面标签 -->
      <div class="layadmin-pagetabs" id="LAY_app_tabs">
        <div class="layui-icon layadmin-tabs-control layui-icon-prev" layadmin-event="leftPage"></div>
        <div class="layui-icon layadmin-tabs-control layui-icon-next" layadmin-event="rightPage"></div>
        <div class="layui-icon layadmin-tabs-control layui-icon-down">
          <ul class="layui-nav layadmin-tabs-select" lay-filter="layadmin-pagetabs-nav">
            <li class="layui-nav-item" lay-unselect>
              <a href="javascript:;"></a>
              <dl class="layui-nav-child layui-anim-fadein">
                <dd layadmin-event="closeThisTabs"><a href="javascript:;">关闭当前标签页</a></dd>
                <dd layadmin-event="closeOtherTabs"><a href="javascript:;">关闭其它标签页</a></dd>
                <dd layadmin-event="closeAllTabs"><a href="javascript:;">关闭全部标签页</a></dd>
              </dl>
            </li>
          </ul>
        </div>
        <div class="layui-tab" lay-unauto lay-allowClose="true" lay-filter="layadmin-layout-tabs">
          <ul class="layui-tab-title" id="LAY_app_tabsheader">
            <li lay-id="home/console.html" lay-attr="${ctx}/mgr/welcome" class="layui-this">工作台</li>
          </ul>
        </div>
      </div>
      
      <!-- 主体内容 -->
      <div class="layui-body" id="LAY_app_body">
        <div class="layadmin-tabsbody-item layui-show">
          <iframe src="${ctx}/mgr/welcome" frameborder="0" class="layadmin-iframe"></iframe>
        </div>
      </div>
      
      <!-- 辅助元素，一般用于移动设备下遮罩 -->
      <div class="layadmin-body-shade" layadmin-event="shade"></div>
    </div>
  </div>
  <script>
	  layui.config({
	    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
	  }).extend({
	    index: 'lib/index' //主入口模块
	  }).use(['index','set','form'],function(){
		  	var form = layui.form;
		  	var layer = layui.layer;
			var $ = layui.$;
			$('#editOrg').val("${bindOrgId}-${bindDeptId}");
			form.render();
			// 获取数据并绑定
			$.getJSON('${ctx}/mgr/navi', function (data) {
				var _menus = data;
				_menus_length = data.length;//一级菜单数
				var menuHtml = '';
				$.each(_menus, function (i, n) {
					var id = n.id;
					menuHtml = menuHtml + '<li data-name="'+n.menuCode+'" ';
					menuHtml = menuHtml + 'class="layui-nav-item ';
					if(i == 0){
						menuHtml = menuHtml + 'layui-nav-itemed';
					}
					menuHtml = menuHtml + '">';
					menuHtml = menuHtml + '<a href="javascript:;" lay-tips="'+n.text+'" lay-direction="2">';
					menuHtml = menuHtml + '    <i class="layui-icon '+n.iconCls+'"></i>';
					menuHtml = menuHtml + '    <cite>'+n.text+'</cite>';
					menuHtml = menuHtml + '  </a>';
					var _menuchild_length = n.children.length;
					if(_menuchild_length > 0){
						var childmenus = n.children;
						menuHtml = menuHtml + '<dl class="layui-nav-child">';
						$.each(childmenus, function (ind, nc) {
							var id = nc.id;
							menuHtml = menuHtml + '<dd data-name="'+nc.menuCode+'" >';
							if(nc.children != null){
								var _secendchild_length = nc.children.length;
								if(_secendchild_length > 0){
									menuHtml = menuHtml + '  <a href="javascript:;">'+nc.text+'</a>';
									var childmenus = nc.children;
									menuHtml = menuHtml + '<dl class="layui-nav-child">';
									$.each(childmenus, function (index, ncc) {
										menuHtml = menuHtml + '<dd data-name="'+ncc.menuCode+'" >';
										menuHtml = menuHtml + '  <a lay-href="'+basePath+ncc.menuUrl+'">'+ncc.text+'</a>';
										menuHtml = menuHtml + '</dd>';
									});
								}
							}else{
								menuHtml = menuHtml + '  <a lay-href="'+basePath+nc.menuUrl+'">'+nc.text+'</a>';
							}
							menuHtml = menuHtml + '</dd>';
						});
						menuHtml = menuHtml + ' </dl>';
					}
				menuHtml = menuHtml + ' </li>';
			});
			$("#LAY-system-side-menu").append(menuHtml);
		    layui.element.render();
		}).success(function(){})
		.error(function() { layer.alert('菜单加载失败，请刷新重试~', {icon: 7}); })
			
		    // 正则校验
		    form.verify({
		    	 pass: [
		    	    /^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)^.{8,16}$/
		    	    ,'必须同时包含大写字母、小写字母、数字'
		    	  ] 
	    	});  
		  	// 修改密码提交
		    form.on('submit(lay-edit-pwd-submit)', function(obj){
		    	$.post('${ctx}/mgr/editPwd', obj.field, function(result) {
		    		if (result.success) {
						layer.msg('密码修改成功~',{icon: 1});
						layer.closeAll('page');
					}else{
						layer.msg(result.msg,{icon: 7});
					}
				});
		    });
		  	// 切换公司部门
		    form.on('submit(lay-edit-org-submit)', function(obj){
		    	$.post('${ctx}/mgr/switchOrgDept', obj.field, function(result) {
		    		if (result.success) {
						//layer.msg('切换公司部门成功~',{icon: 1});
						$("#showOrgDept").html(result.msg);
						layer.closeAll('page');
						form.render();
					}else{
						layer.msg(result.msg,{icon: 7});
					}
				});
		    });
	  });
  </script>
  
</body>
</html>


